package com.zhiyou.servlet.rect;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zhiyou.service.RectService;
import com.zhiyou.serviceImpl.RectServiceImpl;

/**
 * Servlet implementation class RectUpdateServlet
 */
@WebServlet("/RectUpdateServlet")
public class RectUpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RectUpdateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		RectService rs = new RectServiceImpl();
		int flat = Integer.parseInt(request.getParameter("flat_id"));
		int tenant = Integer.parseInt(request.getParameter("tenant_id"));
		double money = Double.parseDouble(request.getParameter("r_money"));
		String remark = request.getParameter("r_remark");
		int id = Integer.parseInt(request.getParameter("r_id"));
		Object obj[] = {flat,tenant,money,remark,id};
		boolean flag = rs.update(obj);
		if(flag){
			request.setAttribute("msg", "修改成功");
			request.getRequestDispatcher("/RectShowServlet?1=1").forward(request, response);
		}else{
			request.setAttribute("msg", "修改失败");
			request.getRequestDispatcher("/view/rect/update.jsp").forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
